﻿var search = {
    regInt: /^[a-z0-9]+$/,
    defNickName: "请输入昵称或部分昵称",
    JYSearchName: "hideSearch",
    hideSearch: [],
    expandArray: [{
        name: "身高",
        cons: ["height_start", "height_end"]
    }, {
        name: "住房",
        cons: ["house"]
    }, {
        name: "月薪",
        cons: ["salary"]
    }, {
        name: "购车",
        cons: ["car"]
    }, {
        name: "学历",
        cons: ["education", "education_end"]
    }, {
        name: "婚史",
        cons: ["marriage"]
    }, {
        name: "职业",
        cons: ["career"]
    }, {
        name: "生育",
        cons: ["children"]
    }, {
        name: "籍贯",
        cons: ["birth_province"]
    }, {
        name: "星座",
        cons: ["constellation"]
    }],
    init: function (a) {//初始化对象
        this.JYSearchName = "hideSearch" + a.userId || this.JYSearchName;
        this._start(a);
        this._event(a);
        this.bindBtn()
    },
    _start: function (b) {
        var c = this;
        var a = "";
        var f = "";
        var d = false;
        for (var h in window.provPyData) {
            if (this.regInt.test(h)) {
                f += "<a data='" + h + "'>" + window.provPyData[h]["name"] + "</a>"
            }
            if (!d && -1 == $.inArray(h, window.hotCitys)) {
                d = true;
                f += "<br />"
            }
        }
        $("#id_search_prov_ul p").html(f);
        $("#id_birth_prov_ul p").html(f);
        var g = new Array();
        for (var e = 0; e < $("#searchwrapper div.sel").length; e++) {
            g.push(new HoverSelect({
                container: "#searchwrapper div.sel:nth(" + e + ")",
                field: "input[type=hidden]",
                label: "span",
                ul: "div",
                li: "p"
            }))
        }
        window._getHoverSelectByName = function (m) {
            for (var n = 0, o; n < g.length; n++) {
                o = g[n];
                if (m === o.getName()) {
                    return o;
                    break
                }
            }
        };
        var l = window._getHoverSelectByName("search_province");//省
        var k = window._getHoverSelectByName("birth_province");
        l.init(b.provInit);
        k.init(b.birthInit);
        if (b.constellation) {
            var j = window._getHoverSelectByName("constellation");
            j.init(b.constellation)
        }

        l.onchange(function (r) {
            if (c.regInt.test(r)) {
                var q = window.provPyData[r]["city"];
                var m = "";
                if (-1 !== $.inArray(r, window.hotCitys)) {
                    m = ""
                }
                for (var o = 0, s = q.length; o < s; ++o) {
                    m += "<a data='" + q[o][2] + "'>" + q[o][1] + "</a>"
                }
                $("#id_search_city_ul p").html(m)
            }
        });
        k.onchange(function (r) {
            if (c.regInt.test(r)) {
                var q = window.provPyData[r]["city"];
                var m = "";
                if (-1 !== $.inArray(r, window.hotCitys)) {
                    m = ""
                }
                for (var o = 0, s = q.length; o < s; ++o) {
                    m += "<a data='" + q[o][2] + "'>" + q[o][1] + "</a>"
                }
                $("#id_birth_city_ul p").html(m)
            }
        });
        var city = "";
        $("#id_search_city_ul a").live("click", function () {
            $("#id_search_city_ul").fadeOut();
            $("#id_search_zhen_ul").fadeIn();
            r = $(this).attr("data");//当前城市
            city = $(this).text();
            t = l.getProv();//省
                var q = window.provPyData[t][r];
                var m = "";
                if (q != undefined) {
                    for (var o = 0, s = q.length; o < s; ++o) {
                        m += "<a data='" + q[o][2] + "'>" + q[o][1] + "</a>"
                    }
                }
            else
                {
                    m += "<a data=' '>不限镇</a>"
                }
                $("#id_search_zhen_ul p").html(m)
        });

        $("#id_search_zhen_ul a").live("click", function () {
            $("#id_search_zhen_ul").fadeOut();
            $("#id_search_prov").val(l.getProv());
            $("#id_search_city").val(city);
            $("#id_search_zhen").val($(this).attr("data"));
            var i = window.provPyData[l.getProv()]["name"];
            if ($(this).attr("data") != -1) {
                i =i+city+ $(this).text()
            }
            l.getLabel().text(i)
        });
        $("#id_birth_city_ul a").live("click", function () {
            $("#id_birth_city_ul").fadeOut();
            $("#id_birth_prov").val(k.getProv());
            $("#id_birth_city").val($(this).attr("data"));
            var i = window.provPyData[k.getProv()]["name"];
            if ($(this).attr("data") != -1) {
                i += $(this).text()
            }
            k.getLabel().text(i)
        })
    },
    _event: function (b) {
        var a = this;
        $("#add_search_cons a").live("click", function () {
            var c = $(this).attr("lid");
            a.hideSearch.splice($.inArray(c, a.hideSearch), 1);
            $("#ex_s_" + c).show();
            $(this).remove()
        });
        $("div.sdel a").click(function () {
            var c = $(this).attr("id").split("_");
            c = c[2];
            a.hideSearch.push(c);
            $("#ex_s_" + c).hide();
            $("#add_search_cons").append($("<a href='javascript:;' lid='" + c + "'>+ " + a.expandArray[c].name + "</a>"))
        });
        $("#id_nickname").focus(function () {
            if ($(this).val() == a.defNickName) {
                $(this).val("")
            }
        }).blur(function () {
            if ($(this).val() == "") {
                $(this).val(a.defNickName)
            }
        });
        $("#nick_search").mouseenter(function () {
            $("#nick_search").attr("class", "name-searchhover");
            $("#nick_search_menu").show()
        }).mouseleave(function () {
            $("#nick_search_menu").hide();
            $("#nick_search").attr("class", "name-search")
        });
        $("#nick_search_menu").mouseenter(function () {
            $("#nick_search").attr("class", "name-searchhover");
            $(this).show()
        }).mouseleave(function () {
            $("#nick_search").attr("class", "name-search");
            $(this).hide()
        });
        $("#expandSearch").click(function () {
            $(this).hide();

            $("#searchForm_btn_01").hide();
            $("#expandSearchForm").show();
            $("#searchForm_btn_02").parent().show();
            $("#searchwrapper").attr("class", "searchwrapper1")
        });
        $("#closeSearch").click(function () {
            $("#expandSearch").show();
            $("#searchForm_btn_01").show();
            $("#expandSearchForm").hide();
            $("#searchForm_btn_02").parent().hide();
            $("#searchwrapper").attr("class", "searchwrapper")
        });
        $("#expandSearch1").click(function () {
            $(this).hide();
            $("#id_search_simg_logo").attr("class", "simg");
            $("#id_search_history_str").hide();
            $("#id_search_history_table").show();
            $("#searchForm_btn_01").hide();
            $("#expandSearchForm").show();
            $("#searchForm_btn_02").parent().show();
            $("#searchwrapper").attr("class", "searchwrapper1")
        });
        $("#closeSearch1").click(function () {
            $("#expandSearch1").show();
            $("#id_search_simg_logo").attr("class", "simg1");
            $("#id_search_history_str").show();
            $("#id_search_history_table").hide();
            $("#expandSearchForm").hide();
            $("#searchForm_btn_02").parent().hide();
            $("#searchwrapper").attr("class", "searchwrapper")
        })
    },
    bindBtn: function () {
        var a = this;
        $("#searchForm_btn_01, #searchForm_btn_02, #searchForm_btn_03").click(function () {
            var b = ["city", "sex", "age_start", "age_end", "photo"];
            var h = $(this).attr("id");
            if (h == "searchForm_btn_03") {
                b.push("nickname")
            } else {
                if (h == "searchForm_btn_02") {
                   // GJ.setCookie(a.JYSearchName, a.hideSearch.join(","), 3600 * 24 * 365, "/");
                    for (var d in a.expandArray) {
                        if (-1 == $.inArray(d, a.hideSearch)) {
                            for (var e in a.expandArray[d].cons) {
                                b.push(a.expandArray[d].cons[e])
                            }
                        }
                    }
                }
            }
            var g = "/";
            var c = "";
            $.each(b, function (m, o) {
                switch (o) {
                    case "city":
                        var f = $("#id_search_prov").val();
                        var p = $("#id_search_city").val();
                        if (-1 != $.inArray(f, window.hotCitys)) {
                            g += f + "/";
                            c += "&district=" + p
                        } else {
                            g += p + "/"
                        }
                        break;
                    case "birth_province":
                        var f = $("#id_birth_prov").val();
                        var p = $("#id_birth_city").val();
                        if (f != -1 || f) {
                            if (-1 != $.inArray(f, window.hotCitys)) {
                                c += "&birth_city=" + f;
                                c += "&birth_district=" + p
                            } else {
                                c += "&birth_province=" + f;
                                c += "&birth_city=" + p
                            }
                        }
                        break;
                    case "sex":
                        g += $("#id_search_" + o).val() + "/";
                        break;
                    case "photo":
                        var k = $("#selectPhoto");
                        if (k.attr("checked")) {
                            photo = 1
                        } else {
                            photo = 0
                        }
                        c += "&" + o + "=" + photo;
                        break;
                    case "education":
                    case "salary":
                        var n = $("#id_" + o).val();
                        if (n != 0 && n != null) {
                            c += "&" + o + "=" + n;
                            if ($("#id_" + o + "_end").attr("checked")) {
                                c += "&" + o + "_end=" + $("#id_" + o + "_end").val()
                            }
                        }
                        break;
                    case "age_start":
                    case "age_end":
                        var n = $("#id_search_" + o).val();
                        if (n != 0 && n != null) {
                            c += "&" + o + "=" + n
                        }
                        break;
                    case "marriage":
                    case "height_start":
                    case "height_end":
                    case "house":
                    case "car":
                    case "career":
                    case "children":
                    case "constellation":
                        var n = $("#id_" + o).val();
                        if (n != 0 && n != null && n != "0,1,2,3,4,5,6,7,8,9,10,11,12") {
                            c += "&" + o + "=" + n
                        }
                        break;
                    case "nickname":
                        var j = $("#id_nickname").val();
                        j = j.replace(/[_\'\"\s]/g, "");
                        if (j && j.length > 0) {
                            c += "&nickname=" + encodeURIComponent(j)
                        }
                        break;
                    case "id_set":
                        var l = $("#" + o).val();
                        if (l != "") {
                            c += "&" + l + "=1"
                        }
                        break
                }
            });
           // GJ.setCookie("jy_search_record_remember_flag", 1, 3600 * 24, "/", ".com");
            location.href = "/Channel/UserSearch.aspx?" + c.substr(1);
            return false
        })
    }
};
window.onload=search;
  var   HoverSelect = function (i) {
        var d = $(i.container);
        var l = d.attr("id");
        if (-1 != $.inArray(l, ["id_search", "id_birth"])) {
            i.li = "a";
            i.ul = "#" + l + "_prov_ul";
            i.filed = "#" + l + "_prov";
            var g = "bj",
				a = -1
        } else {
            if (l == "id_con_expand") {
                i.li = "input[name          = id_con_expand_li]";
                i.ul = "#id_con_expand_ul";
                i.filed = "#id_constellation";
                var k = [];
                var o = []
            }
        }
        var n = d.find(i.label),
			m = d.find(i.field),
			c = d.find(i.ul),
			b = c.find(i.li),
			h = -1,
			f = i.onchange || null,
			j = i.onselect || null,
			e = false;
        if (l == "id_search" || l == "id_birth") {
            d.hover(function (p) {
                var q = $("#" + l + "_city_ul").css("display");
                if (q === "none") {
                    e = true;
                    d.css("z-index", 99);
                    c.show()
                }
            }, function (p) {
                var q = $("#" + l + "_city_ul").css("display");
                if (q === "none") {
                    e = false;
                    d.css("z-index", 0);
                    m.blur()
                }
                c.hide()
            });
            b.each(function (p) {
                $(b[p]).click(function (q) {
                    m.blur();
                    g = $(this).attr("data");
                    e = false;
                    c.hide();
                    $("#" + l + "_city_ul").fadeIn();
                    if (h !== p && "function" === typeof (f)) {
                        f.call(null, g)
                    }
                    if ("function" === typeof (j)) {
                        j.call(null, g)
                    }
                    h = p
                }).mouseenter(function () {
                    $(this).addClass("hover")
                }).mouseleave(function () {
                    $(this).removeClass("hover")
                })
            })
        } else {
            if (l == "id_con_expand") {
                d.hover(function (p) {
                    e = true;
                    d.css("z-index", 99);
                    c.show()
                }, function (p) {
                    e = false;
                    d.css("z-index", 0);
                    c.hide();
                    m.blur()
                });
                b.each(function (p) {
                    $(b[p]).click(function (q) {
                        m.blur();
                        e = false;
                        c.hide();
                        if ($(this).attr("checked")) {
                            if (k.length >= 5) {
                                $(this).attr("checked", false);
                                return false
                            }
                            k.push($(this).val());
                            o.push($(this).attr("data"));
                            m.val(k.join(","));
                            n.text(o.join(",").substr(0, 10))
                        } else {
                            k.splice($.inArray($(this).val(), k), 1);
                            o.splice($.inArray($(this).attr("data"), o), 1);
                            if (k.length <= 0) {
                                m.val("0");
                                n.text("不限")
                            } else {
                                m.val(k.join(","));
                                n.text(o.join(",").substr(0, 10))
                            }
                        }
                        $("#" + l + "_city_ul").fadeIn();
                        if (h !== p && "function" === typeof (f)) {
                            f.call(null, g)
                        }
                        if ("function" === typeof (j)) {
                            j.call(null, g)
                        }
                        h = p
                    }).mouseenter(function () {
                        $(this).addClass("hover")
                    }).mouseleave(function () {
                        $(this).removeClass("hover")
                    })
                })
            } else {
                d.hover(function (p) {
                    e = true;
                    d.css("z-index", 99);
                    c.show()
                }, function (p) {
                    e = false;
                    d.css("z-index", 0);
                    c.hide();
                    m.blur()
                });
                b.each(function (p) {
                    $(b[p]).click(function (q) {
                        $(this).siblings().removeClass("hover");
                        $(this).addClass("hover");
                        m.blur();
                        n.text($(this).text());
                        e = false;
                        c.hide();
                        m.val($(this).attr("data"));
                        if (h !== p && "function" === typeof (f)) {
                            f.call(null, m.val())
                        }
                        if ("function" === typeof (j)) {
                            j.call(null, m.val())
                        }
                        h = p
                    }).mouseenter(function () {
                        $(this).addClass("hover")
                    }).mouseleave(function () {
                        $(this).removeClass("hover")
                    })
                })
            }
        }
      ////


        this.getName = function () {
            return m.attr("name")
        };
        this.onchange = function (p) {
            f = p;
            return this
        };
        this.onselect = function (p) {
            j = p;
            return this
        };
        this.expand = function () {
            d.css("z-index", 99);
            c.show();
            return this
        };
        this.getProv = function () {
            return g
        };
        this.getLabel = function () {
            return n
        };
        this.init = function (r) {
            if (l == "id_con_expand") {
                for (var q in r) {
                    b[r[q] - 1].click()
                }
            } else {
                g = r.prov || r.city || g;
                a = r.dis || r.city || a;
                var p = window.provPyData[g]["name"];
                if (a != -1 && a) {
                    for (var q in window.provPyData[g]["city"]) {
                        if (window.provPyData[g]["city"][q][2] == a) {
                            p += window.provPyData[g]["city"][q][1];
                            break
                        }
                    }
                }
                n.text(p);
                if (l == "id_birth" && !r.city) { } else {
                    m.val(g);
                    $("#" + l + "_city").val(a)
                }
            }
        };
        return this
    }